<template>
    <div class="search" style="margin: 20px;width: 960px;">
        <el-card class="box-card" style="display: flex;flex-wrap: wrap;" v-show="!isshow">
            <div v-for="item in searchlist" :key="item.id" class="text item"
                style="display: flex;width: 220px;flex-direction: column;justify-content: center; align-items: center;padding: 10px 0;flex-wrap: wrap;">
                <el-image style="width: 100px; height: 100px;border-radius: 15px;" :src="item.postImg"
                    :fit="fit"></el-image>
                <el-link :underline="false" style="margin-top: 12px;" @click="toDetail(item.postId,item.postType,item.author)">{{ item.title }}</el-link>
            </div>
        </el-card>
        <el-empty :image-size="200" v-show="isshow"></el-empty>
    </div>
  
  </template>
  
  
  <script>
  // 导入api
  import API from "@/api/request";
  export default {
    inject: ['reload'],
    data() {
        return {
            user: {},
            searchlist: [],
            searchText:"",
            isshow:false
        }
    },
    methods: {
        getsearchlist() {
            API.get("/api/plateManagement/search", {
                params: {
                    "searchText": this.searchText
                }
            }).then(res => {
                if (res.data.code == 200) {
                    console.log(res)
                    this.searchlist = res.data.data;
                    console.log(res.data.data)
                    console.log(this.searchlist)
                    if(this.searchlist.length==0){
                        this.isshow=true;
                    }
                }
  
            })

        },
        //跳转详情页
        toDetail(id, type, stuId) {
            console.log("点击了")
            this.$router.push({ path: '/detail', query: { id: id, type: type, stuId: stuId } })
        }
  
    },
    created() {
        this.user = sessionStorage.getItem('user') ? JSON.parse(sessionStorage.getItem('user')) : {}
       this.searchText=this.$route.query.searchText
        console.log(this.user)
        this.getsearchlist();
    },
   
  };
  </script>
  
  <style scoped>
  .el-row {
    margin-bottom: 20px;
  
    &:last-child {
        margin-bottom: 0;
    }
  }
  
  .el-col {
    border-radius: 4px;
  }
  
  .bg-purple-dark {
    background: #99a9bf;
  }
  
  .bg-purple {
    background: #d3dce6;
  }
  
  .bg-purple-light {
    background: #e5e9f2;
  }
  
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
  
  >>> .el-card__body, .el-main {
    padding: 20px;
    display: flex;
  }

 >>> .el-card__body{
    display: flex;
    flex-wrap: wrap;
  }
  </style>